import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  // 登录组件
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    // 管理系统主页
    path: '/',
    component: Layout,
    redirect: '/personalMessage/myMessage',
    meta: {
      title: '个人信息',
      icon: 'el-icon-message'
    },
    children: [{
      // 我的消息组件
      path: '/personalMessage/myMessage',
      name: 'MyMessage',
      component: () => import('@/views/personalMessage/myMessage'),
      meta: { title: '我的消息' }
    }, {
      // 修改信息组件
      path: '/personalMessage/editMessage',
      name: 'EditMessage',
      component: () => import('@/views/personalMessage/editMessage'),
      meta: { title: '修改信息' }
    },
    {
      // 消息详情组件
      path: '/personalMessage/myMessage/messageDetail',
      component: () => import('@/views/personalMessage/myMessage/messageDetail'),
      name: 'messageDetail',
      hidden: true,
      meta: { title: '消息详情' }
    },
    {
      // 消息详情组件,
      path: '/personalMessage/myMessage/remark',
      component: () => import('@/views/personalMessage/myMessage/remark'),
      name: 'Remark',
      hidden: true,
      meta: { title: '备注' }
    }, {
      // 修改账号组件
      path: '/personalMessage/editMessage/editAccount',
      name: 'EditAccount',
      hidden: true,
      component: () => import('@/views/personalMessage/editMessage/editAccount'),
      meta: { title: '修改账号' }
    }, {
      // 修改密码组件
      path: '/personalMessage/editMessage/editPassword',
      name: 'EditPassword',
      hidden: true,
      component: () => import('@/views/personalMessage/editMessage/editPassword'),
      meta: { title: '修改密码' }
    }]
  }, {
    // 供应商信息组件
    path: '/supplierMessage/index',
    component: Layout,
    children: [
      {
        path: '/supplierMessage',
        name: 'SupplierMessage',
        component: () => import('@/views/supplierMessage/index'),
        meta: { title: '供应商信息', icon: 'form' }
      },
      {
        // 添加供应商信息
        path: '/supplierMessage/addSupplier',
        name: 'AddSupplier',
        component: () => import('@/views/supplierMessage/addSupplier'),
        hidden: true,
        meta: { title: '添加供应商' }
      },
      {
        // 查看供应商信息
        path: '/supplierMessage/checkSupplier',
        name: 'CheckSupplier',
        component: () => import('@/views/supplierMessage/checkSupplier'),
        hidden: true,
        meta: { title: '查看供应商' }
      },
      {
        // 编辑供应商信息
        path: '/supplierMessage/editSupplier',
        name: 'EditSupplier',
        component: () => import('@/views/supplierMessage/editSupplier'),
        hidden: true,
        meta: { title: '编辑供应商' }
      }
    ]
  }, {
    // 客户管理部分
    path: '/customer',
    component: Layout,
    redirect: '/customer/customerMessage',
    name: 'Customer',
    meta: { title: '客户管理', icon: 'el-icon-s-custom' },
    children: [
      {
        // 客户信息组件
        path: '/customer/customerMessage',
        name: 'CustomerMessage',
        component: () => import('@/views/customer/customerMessage'),
        meta: { title: '客户信息' }
      },
      {
        // 虚拟仓组件
        path: '/customer/virtualWarehouse',
        name: 'VirtualWarehouse',
        component: () => import('@/views/customer/virtualWarehouse'),
        meta: { title: '虚拟仓' }
      }, {
        // 分配客户组件
        path: '/customer/assignCustomerService',
        name: 'AssignCustomerService',
        component: () => import('@/views/customer/assignCustomerService'),
        meta: { title: '分配客服' }
      }, {
        // 添加客户组件
        path: '/customer/customerMessage/addCustomer',
        name: 'AddCustomer',
        hidden: true,
        component: () => import('@/views/customer/customerMessage/addCustomer'),
        meta: { title: '添加客户' }
      }, {
        // 编辑客户组件
        path: '/customer/customerMessage/editCustomer',
        name: 'EditCustomer',
        hidden: true,
        component: () => import('@/views/customer/customerMessage/editCustomer'),
        meta: { title: '编辑客户' }
      },
      {
        // 开通虚拟仓页面
        path: '/customer/virtualWarehouse/openVirtualWarehouse',
        name: 'OpenVirtualWarehouse',
        hidden: true,
        component: () => import('@/views/customer/virtualWarehouse/openVirtualWarehouse'),
        meta: { title: '开通虚拟仓' }
      }]
  }, {
    // 仓库管理组件
    path: '/warehouseManagement/index',
    component: Layout,
    children: [
      {
        path: '/warehouseManagement',
        name: 'WarehouseManagement',
        component: () => import('@/views/warehouseManagement/index'),
        meta: { title: '仓库管理', icon: 'form' }
      }]
  }, {
    // 商品管理部分
    path: '/goodsManage',
    component: Layout,
    redirect: '/goodsManage/typeManage',
    name: 'TypeManage',
    meta: { title: '商品管理', icon: 'el-icon-s-custom' },
    children: [
      {
        // 分类管理组件
        path: '/goodsManage/typeManage',
        name: 'TypeManage',
        component: () => import('@/views/goodsManage/typeManage'),
        meta: { title: '分类管理' }
      },
      {
        // 商品信息组件
        path: '/goodsManage/goodsInformation',
        name: 'GoodsInformation',
        component: () => import('@/views/goodsManage/goodsInformation'),
        meta: { title: '商品信息' }
      },
      {
        // 新增商品
        path: '/goodsManage/goodsInformation/addGoods',
        name: 'AddGoods',
        hidden: true,
        component: () => import('@/views/goodsManage/goodsInformation/addGoods'),
        meta: { title: '新增商品' }
      },
      {
        // 编辑商品
        path: '/goodsManage/goodsInformation/editGoods',
        name: 'EditGoods',
        hidden: true,
        component: () => import('@/views/goodsManage/goodsInformation/editGoods'),
        meta: { title: '编辑商品' }
      }]
  },
  {
    // 进货管理部分
    path: '/purchase',
    component: Layout,
    redirect: '/purchase/addReceipt',
    name: 'AddReceipt',
    meta: { title: '进货', icon: 'el-icon-s-custom' },
    children: [
      {
        // 新增入库
        path: '/purchase/addReceipt',
        name: 'AddReceipt',
        component: () => import('@/views/purchase/addReceipt'),
        meta: { title: '新增入库' }
      },
      {
        // 进货记录
        path: '/purchase/purchaseRecord',
        name: 'PurchaseRecord',
        component: () => import('@/views/purchase/purchaseRecord'),
        meta: { title: '进货记录' }
      },
      {
        // 进货退货
        path: '/purchase/purchaseReturn',
        name: 'PurchaseReturn',
        component: () => import('@/views/purchase/purchaseReturn'),
        meta: { title: '进货退货' }
      },
      {
        // 选择供应方
        path: '/purchase/addReceipt/chooseSupplier',
        name: 'ChooseSupplier',
        hidden: true,
        component: () => import('@/views/purchase/addReceipt/chooseSupplier'),
        meta: { title: '选择供应方' }
      }
    ]
  },
  {
    // 销售
    path: '/sale',
    component: Layout,
    redirect: '/sale/addSale',
    name: 'Sale',
    meta: { title: '销售', icon: 'el-icon-s-custom' },
    children: [
      {
        // 新增销售
        path: '/sale/addSale',
        name: 'AddSale',
        component: () => import('@/views/sale/addSale'),
        meta: { title: '新增销售' }
      },
      {
        // 销售记录
        path: '/sale/saleRecord',
        name: 'SaleRecord',
        component: () => import('@/views/sale/saleRecord'),
        meta: { title: '销售记录' }
      },
      {
        // 销售退单
        path: '/sale/saleChargeback',
        name: 'SaleChargeback',
        component: () => import('@/views/sale/saleChargeback'),
        meta: { title: '销售退单' }
      }, {
        // 添加退单
        path: '/sale/saleChargeback/chargeback',
        name: 'Chargeback',
        hidden: true,
        component: () => import('@/views/sale/saleChargeback/chargeback'),
        meta: { title: '添加退单' }
      }
    ]
  }, {
    // 库存管理
    path: '/inventotyManagement',
    component: Layout,
    redirect: '/inventotyManagement/record',
    name: 'InventotyManagement',
    meta: { title: '库存管理', icon: 'el-icon-s-custom' },
    children: [
      {
        // 盘点记录
        path: '/inventoryManagement/record',
        name: 'Record',
        component: () => import('@/views/inventoryManagement/record'),
        meta: { title: '盘点记录' }
      },
      {
        // 库存查询
        path: '/inventoryManagement/inventoryQuery',
        name: 'InventoryQuery',
        component: () => import('@/views/inventoryManagement/inventoryQuery'),
        meta: { title: '库存查询' }
      },
      {
        // 库存告警
        path: '/inventoryManagement/inventoryAlarm',
        name: 'InventoryAlarm',
        component: () => import('@/views/inventoryManagement/inventoryAlarm'),
        meta: { title: '库存告警' }
      }
    ]
  }, {
    // 出库
    path: '/outWarehouse',
    component: Layout,
    redirect: '/outWarehouse/addOutWarehouse',
    name: 'OutWarehouse',
    meta: { title: '出库', icon: 'el-icon-s-custom' },
    children: [
      {
        // 新增出库
        path: '/outWarehouse/addOutWarehouse',
        name: 'AddOutWarehouse',
        component: () => import('@/views/outWarehouse/addOutWarehouse'),
        meta: { title: '新增出库' }
      },
      {
        // 出库记录
        path: '/outWarehouse/outWarehouseRecord',
        name: 'OutWarehousRecord',
        component: () => import('@/views/outWarehouse/outWarehouseRecord'),
        meta: { title: '出库记录' }
      },
      {
        // 异常处理
        path: '/outWarehouse/exceptionHanding',
        name: 'ExceptionHanding',
        component: () => import('@/views/outWarehouse/exceptionHandling'),
        meta: { title: '异常处理' }
      }, {
        // 新增异常处理页面
        path: '/outWarehouse/exceptionHanding/addDeal',
        name: 'AddDeal',
        hidden: true,
        component: () => import('@/views/outWarehouse/exceptionHandling/addDeal'),
        meta: { title: '新增异常' }
      }
    ]
  }, {
    // 系统管理
    path: '/systemManage',
    component: Layout,
    redirect: '/systemManage/roleManage',
    name: 'SystemManage',
    meta: { title: '系统管理', icon: 'el-icon-s-custom' },
    children: [
      {
        // 角色管理
        path: '/systemManage/roleManage',
        name: 'RoleManage',
        component: () => import('@/views/systemManage/roleManage'),
        meta: { title: '角色管理' }
      },
      {
        // 员工管理
        path: '/systemManage/staffManage',
        name: 'StaffManage',
        component: () => import('@/views/systemManage/staffManage'),
        meta: { title: '员工管理' }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: 'Example', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: 'Table', icon: 'table' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: 'Tree', icon: 'tree' }
      }
    ]
  },
  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'),
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
